//
//  CAOrderDoneViewController.m
//  LNH
//
//  Created by twentylx on 2018/2/21.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAOrderDoneViewController.h"
#import "CAOrderDoneView.h"
#import "CAHomeViewController.h"
#import "CAOrderListViewController.h"

@interface CAOrderDoneViewController ()

@property (nonatomic, strong) CAOrderDoneView *orderDoneView;

@end

@implementation CAOrderDoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/// 初始化数据
- (void)lm_initialDefaultsForController {
    
}

/// 绑定 vm
- (void)lm_bindViewModelForController {
    
}

/// 创建视图
- (void)lm_createViewForController {
    [self.view setNeedsUpdateConstraints];
    
    [self.view addSubview:self.orderDoneView];
}

/// 配置导航栏
- (void)lm_configNavigationForController {
    self.title = @"支付完成";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
}

#pragma mark layout
- (void)updateViewConstraints {
    [super updateViewConstraints];
    
    [_orderDoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
}

#pragma mark get & set
- (CAOrderDoneView *)orderDoneView {
    if (!_orderDoneView) {
        _orderDoneView = [CAOrderDoneView new];
        
        [[_orderDoneView.homeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [self backAction];
        }];
        
        [[_orderDoneView.orderButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            CAOrderListViewController *orderListVC = [CAOrderListViewController new];
            orderListVC.status = @"";
            [self.navigationController pushViewController:orderListVC animated:YES];
//            NSString *router = [JLRoutes lm_generateURLWithPattern:LMNavPushRoute parameters:@[NSStringFromClass(CAOrderListViewController.class)] extraParameters:nil];
//            [[RACScheduler mainThreadScheduler] schedule:^{
//                [[UIApplication sharedApplication] openURL:JLRGenRouteURL(LMDefaultRouteSchema, router) options:nil completionHandler:nil];
//            }];
        }];
    }
    return _orderDoneView;
}

#pragma mark private method
- (void) backAction {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

@end
